package com.kla.power.util;

import io.netty.channel.Channel;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CacheUtil {

//    private static Map<String, Object> map = null;


    /**
     * 存储client的channel
     * key:ip value:Channel
     */
    public static Map<String, Channel> map = null;

    private CacheUtil () {

    }

    public static Map getInstance () {
        // 如果对象为空，则证明里面所有socket丢失，为了保证后续正常通信，必须要强制重启充电桩!!!
        if ( map == null ) {
            map = new ConcurrentHashMap<> ();
        }
        return map;
    }

    public static void put ( String key, Channel value ) {
        map.put ( key, value );
    }

    public static Channel get ( String key ) {
        return map.get ( key );
    }

}
